import Vue from 'vue'
import Router from 'vue-router'
import tools from '../utils/util'

Vue.use(Router)
//遍历 module 注册 模块
const mainRouter = ((r) => {
  return r.keys().map((key) => r(key).default)
})(require.context('./main', false, /\.js$/))

//导航 栏的 路由
tools.setData('routers', mainRouter)

//遍历 module 注册 模块
const projectRoutes = ((r) => {
  return r.keys().map((key) => r(key).default)
})(require.context('./project', false, /\.js$/))

const routers = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
  },
  {path: '/404', component: () => import('@/views/404')},
].concat(mainRouter, projectRoutes)

export default new Router({
  mode: 'history', // 后端支持可开
  scrollBehavior: () => ({y: 0}),
  routes: routers
})
